package com.example.hongyu.avtt.ui.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;

import com.example.hongyu.avtt.R;
import com.example.hongyu.avtt.event.Event;
import com.example.hongyu.avtt.model.Txt;
import com.example.hongyu.avtt.model.entity.BaseResponse;
import com.example.hongyu.avtt.network.BaseObserver;
import com.example.hongyu.avtt.network.RetrofitHelper;
import com.example.hongyu.avtt.network.RxUtil;
import com.example.hongyu.avtt.network.api.AppInfoApi;
import com.example.hongyu.avtt.ui.base.BaseActivity;

import butterknife.BindView;

public class TxtReadActivity extends BaseActivity {
    @BindView(R.id.txt_content)
    TextView textureView;
    private String url="";
    private String name="";
    private int id=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void initActivityData() {
        if (id>0) {
            httpFindTxt();
        }

    }

    @SuppressLint("AutoDispose")
    private void httpFindTxt() {
        RetrofitHelper.create(AppInfoApi.class)
                .fiondTxt(id)
                .compose(RxUtil.observervableToMain())
                .subscribe( new BaseObserver<Txt>(getLoadingDialog()){
                    @Override
                    public void onSuccess(BaseResponse<Txt> response) {
                        if (response!=null&&response.getData()!=null){
                            findTxtSucces(response.getData());
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);

                    }
                });
    }

    private void findTxtSucces(Txt txt) {
        textureView.setText(txt.getContent());
        textureView.setMovementMethod(LinkMovementMethod.getInstance());
    }

    @Override
    protected void initContentView() {
        mBundle=getBundle();
        url=mBundle.getString("PLAYURL");
//        url="http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8";
        name= mBundle.getString("PLAYNAME");
        id=mBundle.getInt("PlayId");

    }

    @Override
    protected int getContentView() {
        return R.layout.activity_txt_read;
    }

    @Override
    protected void onEventProcess(Event event) {

    }
}